<?php
namespace app\service;

use app\model\GoodsCateModel;
use plugin\admin\app\common\Tree;
use const support\CORRECT;

class GoodsCateService
{

    //获取分类列表
    public static function treeLists(): array
    {
        $lists=GoodsCateModel::where([
            'status'=>CORRECT
        ])->select(['id','cate_title','cate_id'])->get()->toArray();
        $tree = new Tree($lists,'cate_id');
        return $tree->getTree();
    }

    //获取特定分类下所有分类ID
    public static function  getCateIdsByFid($cateIds): array
    {
        $lists=GoodsCateModel::where([
            'status'=>CORRECT
        ])->select(['id','cate_title','cate_id'])->get()->toArray();
        $tree = new Tree($lists,'cate_id');
        return $tree->getDescendant($cateIds,true);
    }

}